package com.googlecode.galaxyrise.musiclib.server.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.googlecode.galaxyrise.musiclib.server.domain.Track;

/**
 * JPA implementation of the <code>TrackDao</code> interface.
 * 
 * @author Igor Jose Topcin <igortopcin@gmail.com>
 */
@Repository
public class HibernateTrackDaoImpl implements TrackDao {
	
    @Autowired
    private SessionFactory sf;
    
	@SuppressWarnings("unchecked")
    public List<Track> getAlbumTracks(Long albumId) throws DataAccessException {
	    Query q = sf.getCurrentSession().createQuery("from Track t where t.album.id = :albumId");
	    q.setParameter("albumId", albumId);
	    return q.list();
	}

}
